<?php
namespace app\index\controller;
use think\Db;
class Index extends Base{
    public function index(){
    	$banner=Db::name('banner')->where('state',1)->order('sort desc')->select();
    	$server_area_title=Db::name('server_area_title')->where('id',1)->find();
    	$server_area=Db::name('server_area')->order('sort desc')->select();
    	$ciya_reason_title=Db::name('ciya_reason_title')->where('id',1)->find();
    	$ciya_reason=Db::name('ciya_reason')->order('sort desc')->select();
    	$solutions_title=Db::name('solutions_title')->where('id',1)->find();
    	$solutions=Db::name('solutions')->order('sort desc')->select();
    	$partners_title=Db::name('partners_title')->where('id',1)->find();
    	$cases=Db::name('cases')->order('sort desc')->limit(6)->select();
        $news_cate=Db::name('news_cate')->where('state',1)->order('id asc')->limit(3)->select();
        foreach ($news_cate as $key => $value) {
        	$news_cate[$key]['newsarr']=Db::name('news')->where('state',1)->where('c_id',$news_cate[$key]['id'])->order('id desc')->limit(5)->select();
        }
        $headquarters_branches=Db::name('headquarters_branches')->order('sort desc')->select();
        $others=Db::name('others')->where('state',1)->order('sort desc')->select();
        $this->assign('system_set',$this->system_set());
		$this->assign('banner',$banner);
        $this->assign('tmdurl',$this->request->domain());
		$this->assign('server_area_title',$server_area_title);
		$this->assign('server_area',$server_area);
		$this->assign('ciya_reason_title',$ciya_reason_title);
		$this->assign('ciya_reason',$ciya_reason);
		$this->assign('solutions_title',$solutions_title);
		$this->assign('solutions',$solutions);
		$this->assign('partners_title',$partners_title);
		$this->assign('cases',$cases);
        $this->assign('news_cate',$news_cate);
        $this->assign('headquarters_branches',$headquarters_branches);
        $this->assign('others',$others);
        return $this->fetch();
    }
    public function messageup()
    {
        if(!empty(input("param.username"))){
            $data['username']=input("param.username");
        }else{
            return json(['code' => 501, 'msg' => '请输入姓名']);
        }
        if(!empty(input("param.userphone"))){
            $data['userphone']=input("param.userphone");
        }else{
            return json(['code' => 502, 'msg' => '请输入电话']);
        }
        $data['time']=time();
        $data['ip']=$_SERVER["REMOTE_ADDR"];
        $exit=Db::name('message')->where('time','>',time()-60)->where('ip',$data['ip'])->order('id desc')->find();
        if($exit){
            return json(['code' => 503, 'msg' => '提交过于频繁']);
        }
        $res=Db::name('message')->insert($data);
        if($res){
            return json(['code' => 200, 'msg' => '提交成功']);
        }else{
            return json(['code' => 500, 'msg' => '提交失败']);
        }
    }
}
